import { ADD_USER,GET_USERS,REMOVE_USER } from '../actions/users.action';

const initUsers = {
	users:[]
}

function Users(state=initUsers, action) {
	switch (action.type){
		case ADD_USER:
			action.data.newData=1;
			state.users.push(action.data);
			return {...state,...{users:[...state.users]}};
		case GET_USERS:
			return {...state,...{users:action.users}};
		case REMOVE_USER:
			let users=state.users.filter(user=>user.id!==action.id);
			return {...state,...{users}};
		default:
			return state;
	}
}

export default Users;